﻿using EMan.Common.DependencyInjection;

using TrueCode.DependencyManager;
using TrueCode.DependencyManager.BuildActions.BuidBit;
using TrueCode.DependencyManager.BuildActions.Injection;
using TrueCode.DependencyManager.BuildActions.Instantiating;
using TrueCode.DependencyManager.BuildActions.Lifetime;
using TrueCode.DependencyManager.BuildActions.TypeMapping;
using TrueCode.DependencyManager.Extensions;
using TrueCode.DependencyManager.Extensions.Action.Typed;
using TrueCode.DependencyManager.Services.Instantiating;
using TrueCode.DependencyManager.Services.Parameters;

namespace EMan.Server.DependencyInjection
{
  public class ServerFactory : Factory
  {
    public ServerFactory( Container container ) : base(container){}

    public static Container CreateContainer()
    {
      var container = new Container( typeof (IGetSessionalParameter),
                                  typeof( ISingleton ),
                                  typeof( IMapType ),
                                  typeof( IBuildBit ),
                                  typeof( IFilteringInstantiate ),
                                  typeof( ISingleton ),
                                  typeof( IInstantiate ),
                                  typeof( IInject ) );
      container
        .AddDefaultAction< IFilteringInstantiate >( new InstantiateAccessor() )
        .AddDefaultAction< IInstantiate >( new InstantiateByReflection() )
        .AddDefaultAction< IInject >( new CallMethodByReflection() )

        .AddDefaultService< IConstructorProvider >( new MostParametersCountCtorProvider() )
        .AddDefaultService< IParameterProvider >( new AutoParameterProvider() );
      return container;
    }
  }
}